/*  -*- mode: c; coding: utf-8; c-file-style: "stroustrup"; -*-

    Copyright 2008 Asier Aguirre <asier.aguirre@gmail.com>
    This file is part of Intromit.

    Intromit is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Intromit is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Intromit.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "pyembed.h"
#include <stdlib.h>
#include <stdio.h>

#define PF_TEST               "test_pyembed"
#define PF(fmt, arg...)       do{fprintf(stderr, PF_TEST": "fmt"\n", ##arg);} while(0)
#define PFR(ret, fmt, arg...) do{fprintf(stderr, PF_TEST": "fmt"\n", ##arg); return ret;} while(0)

#define RED_BOLD              "\033[1;31m"
#define RESET                 "\033[0m"

#define PROMPT                PF_TEST"> "
#define PROMPT_COLOR          RED_BOLD""PROMPT""RESET

int main(int narg, char **argv)
{
    pyembed_id id;

    // init
    if(!(id=pyembed_init_args(narg, argv))) PFR(1, "error: pyembed_init");
    if(!pyembed_get_quiet(id)) PF("init");

    // activate command line interaction
    if(!pyembed_command_line_init(id, PROMPT_COLOR, ".test_pyembed_history")) PFR(2, "error: pyembed_command_line_init");

    // refresh command line
    while(pyembed_command_line_refresh(id));

    // finish interactive command line 
    if(!pyembed_command_line_finish(id)) PFR(3, "error: pyembed_command_line_finish");

    // close and exit
    pyembed_finish(id);
    PF("finish: all OK");
    return 0;
}
